package org.goldenport.g3.events.datastore

import org.goldenport.g3.{G3Event, G3Message, G3Command}
import org.goldenport.g3.messages.{Record, RecordSet}
import org.goldenport.g3.messages.datastore.DataStoreManifest
import org.goldenport.g3.events._

/**
 * derived from g3.events.CrudEvents
 * 
 * @since   May. 23, 2010
 * @version Jan.  4, 2011
 * @author  ASAMI, Tomoharu
 */
/**
 * Fetch one record from the record collection.
 */
class DataStoreFetched(
  uri: String, command: G3Command, records: RecordSet,
  single: Boolean = true,
  cause: Option[G3Event] = None
) extends RecordFetched(uri, command, records, single, cause)

/**
 * Qeury records from the record collection.
 */
class DataStoreQueried(
  uri: String, command: G3Command, records: RecordSet,
  cause: Option[G3Event] = None
) extends RecordQueried(uri, command, records, cause)

/**
 * 
 */
class DataStoreValueFetched(
  uri: String, command: G3Command, values: List[AnyRef],
  cause: Option[G3Event] = None
) extends Getted(uri, Some(values), cause)

/**
 * Writes records into the record collection.
 */
class DataStoreInserted(
  uri: String, command: G3Command, records: RecordSet,
  cause: Option[G3Event] = None
) extends RecordInserted(uri, command, records, cause) {
//  def this(uri: String, command: G3Command, record: Record,
//           cause: Option[G3Event] = None) = this(
//    uri, command, RecordSet(record), cause)
}

/**
 * Writes records into the record collection.
 */
class DataStoreUpdated(
  uri: String, command: G3Command, records: RecordSet,
  cause: Option[G3Event] = None
) extends RecordUpdated(uri, command, records, cause) {
//  def this(uri: String, command: G3Command, record: Record,
//           cause: Option[G3Event] = None) = this(
//    uri, command, RecordSet(record), cause)
}

/**
 * Removed records from the record collection.
 */
class DataStoreDeleted(
  uri: String, command: G3Command, cause: Option[G3Event] = None
) extends RecordDeleted(uri, command, cause)

/**
 * Creates a record collection.
 */
class DataStoreCreated(uri: String, source: Option[G3Event] = None) extends Mkcoled(uri, source)

/**
 * Drops a record collection.
 */
class DataStoreDropped(uri: String) extends Deleted(uri)

class DataStoreManifestGetted(uri: String, val manifest: DataStoreManifest) extends Getted(uri, Some(manifest))
